package com.pan.api.driver;


import com.pan.api.config.FilterControllerConfig;
import com.pan.api.config.PanConvertConfig;
import com.pan.api.config.PanFormatConfig;
import com.pan.api.config.impl.PanApiDocConfig;
import com.pan.api.filter.ControllerFilter;
import com.pan.api.convert.PanInformationConvert;
import com.pan.api.entity.ControllerInformation;
import com.pan.api.format.PanFormat;
import com.pan.api.utils.PanRecordUtil;

/**
 * 流程
 * 接收 -> 筛选出Controller控制类 -> 将Controller控制类转换为Information信息类 -> 将Information信息类打印出来
 *
 */
enum PanAPIDocDriverImpl implements PanRecordUtil {
//    public void run(ApplicationContext applicationContext);
    INSTANCE;
    public void run(Object... objs){
        PanApiDocConfig panApiDocConfig = PanApiDocConfig.INSTANCE;
        FilterControllerConfig filterControllerConfig = panApiDocConfig;
        ControllerFilter filterController = filterControllerConfig.getFilterController();
        PanConvertConfig panConvertConfig = panApiDocConfig;
        PanInformationConvert panInformationConvert = panConvertConfig.getPanConvert();
        PanFormatConfig panFormatConfig = panApiDocConfig;
        PanFormat panFormat = panFormatConfig.getPanFormat();
        pan:for (Object o:objs){
            Class<?> clazz = o.getClass();
            clazz  = filterController.filter(clazz);
            if (clazz == null) continue pan;
            ControllerInformation controllerInformation
                    = panInformationConvert.handle(clazz);
            System.out.println("debug Information: "+ controllerInformation.toString());
            String controllerString = panFormat.convert(controllerInformation);
            System.out.println("\n\ndebug format string: "+ controllerString);
            this.write(controllerString);
        }
    }
}
